// Project name:JavaRedis
// Creator:muhong
// Date time:2023/7/31,2:28 下午
// Name:ByteBuf

package io.gmh.buffer;

import io.gmh.util.ReferenceCounted;

public abstract class ByteBuf implements ReferenceCounted, Comparable<ByteBuf>, ByteBufConvertible {

    public abstract int capacity();

    public abstract ByteBuf capacity(int newCapacity);

    public abstract int maxCapacity();

    public abstract ByteBufAllocator alloc();

    public abstract ByteOrder order();

    public abstract ByteBuf unwrap();

    public abstract boolean isDirect();

    public abstract boolean isReadOnly();

    public abstract ByteBuf asReadOnly();

    public abstract int readerIndex();

    public abstract ByteBuf readerIndex(int readerIndex);

    public abstract int writerIndex();

    public abstract ByteBuf writerIndex(int writerIndex);

    public abstract ByteBuf setIndex(int readerIndex, int writerIndex);

    public abstract int readableBytes();

    public abstract int writableBytes();

    public abstract int maxWritableBytes();

    public int maxFastWritableBytes(){
        return writableBytes();
    }

    public abstract boolean isReadable();

    public abstract boolean isReadable(int size);

    public abstract boolean isWritable();

    public abstract boolean isWritable(int size);

    public abstract ByteBuf clear();

    public abstract ByteBuf markReaderIndex();

    public abstract ByteBuf resetReaderIndex();

    public abstract ByteBuf markWriterIndex();

    public abstract ByteBuf resetWriterIndex();

    public abstract ByteBuf discardReadBytes();

    public abstract ByteBuf discardSomeReadBytes();

    public abstract ByteBuf ensureWritable(int minWritableBytes);

    public abstract int ensureWritable(int minWritableBytes, boolean force);

    public abstract boolean getBoolean(int index);

    public abstract byte getByte(int index);

    public abstract short getUnsignedByte(int index);

    public abstract short getShort(int index);

    public abstract short getShortLE(int index);

    public abstract short getUnsignedShort(int index);

    public abstract short getUnsignedShortLE(int index);

    public abstract int getMedium(int index);
    public abstract int getMediumLE(int index);
    public abstract int getUnsignedMedium(int index);
    public abstract int getUnsignedMediumLE(int index);

    public abstract ByteBuf setBytes(int index, ByteBuf src, int srcIndex, int length);

    boolean isAccessible(){
        return refCnt() != 0;
    }

}
